using System.Net;
using System.Text;

namespace hw10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string query;
        private string baseURL = "https://baike.baidu.com/item/";


        private void btnSubmit_Click(object sender, EventArgs e)
        {
            this.query = this.tbxSearch.Text.ToString();
            baseURL += query;
            string content = requestBaidu(baseURL);
            Thread thread1 = new Thread(()=>{ this.addContent(this.tbxContent1, content); });
            Thread thread2 = new Thread(()=>{ this.addContent(this.tbxContent2, content); });
            thread1.Start();
            thread2.Start();
        }

        private void addContent(TextBox box, string content)
        {
            box.AppendText(content);
        }

        private string requestBaidu(string url)
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36";
            string responseStr = null;
            WebResponse response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader =
                    new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                responseStr = reader.ReadToEnd();
                reader.Close();
            }
            return responseStr;
        }


    }
}